package railRoad;

/**
 * Class that presents Ticket data
 * 
 * @author Rukin Oleg
 * 
 */
public class Ticket {
	private int ticket_id;
	private int passenger_id;
	private int route_id;
	private int type;
	private double price = 0.0;
	
	public Ticket()
	{
		this.ticket_id = -1;
		this.passenger_id = -1;
		this.route_id = -1;
		this.type = -1;
		this.price = 0;
	}

	public Ticket(int ticket_id, int passenger_id, int route_id,
			int type, double price) {
		super();
		this.ticket_id = ticket_id;
		this.passenger_id = passenger_id;
		this.route_id = route_id;
		this.type = type;
		this.price = price;
	}

	public int getTicket_id() {
		return ticket_id;
	}

	public void setTicket_id(int ticket_id) {
		this.ticket_id = ticket_id;
	}
	
	public int getPassenger_id() {
		return passenger_id;
	}

	public void setPassenger_id(int passenger_id) {
		this.passenger_id = passenger_id;
	}
	
	public int getRoute_id() {
		return route_id;
	}

	public void setRoute_id(int route_id) {
		this.route_id = route_id;
	}

	/**
	 * Price for this Ticket
	 * 
	 * @return price of this Ticket
	 */
	public double getPrice() {
		return price;
	}

	public void setPrice(double price) {
		this.price = price;
	}

	/**
	 * Get type of ticket
	 * 
	 * @return Type of Ticket: NONE, RESERVED, PURCHASED
	 */
	public int getType() {
		return type;
	}

	/**
	 * Set ticket type
	 * 
	 * @param type
	 *            one from NONE, RESERVED, PURCHASED
	 */
	public void setType(int type) {
		this.type = type;
	}

	@Override
	public String toString() {
		return "Ticket price is " + price;
	}
	
	/**
	 * Checks ticket for able to buy it, and decrees available tickets for {@link#Route} 
	 * @return TRUE if ticket can be bought another FALSE
	 */
	public boolean check() {
		
		Route route = Schedule.getInstance().getRouteById(route_id);
		
		return route.buyTicket();
	}
	
	/**
	 * Return this ticket back, increases available tickets for {@link#Route}  
	 */
	public void returnTicket() {
		Route route = Schedule.getInstance().getRouteById(route_id);
		route.returnTicket();
	}
	/**
	 * Return name of {@link#Route} of this {@link#Ticket}
	 * @return
	 */
	public String getRouteName()
	{
		Route route = Schedule.getInstance().getRouteById(route_id);
		return route.getRouteName();
	}
	
	/**
	 * Return type of string one from {@link#TicketType}
	 * @return
	 */
	public String getTypeName()
	{
		TicketType type = TicketType.values()[this.type];
		return "ticketType." + type.name();
	}
}
